<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
        .upLoadFormDadaDiv{
            position: relative;
            cursor: pointer;
        }
        .upLoadFormDadaDiv #AjaxFileData{
            position: absolute;
            top: 0;left: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="billCode">


    <div class="layui-form-item bh-item">
        <label class="layui-form-label required">快递单号</label>
        <div class="layui-input-block">
            <input type="text" name="expressCode" lay-verify="required" lay-reqtext="请输入快递单号" placeholder="请输入快递单号" value="" class="layui-input">

        </div>
    </div>
        <div class="layui-form-item bh-item">
        <label class="layui-form-label required">发票号</label>
        <div class="layui-input-block">
            <input type="text" name="billNumber" lay-verify="required" lay-reqtext="请输入发票号" placeholder="请输入发票号" value="" class="layui-input">

        </div>
    </div>
    <input type="hidden" name="images" class="image">
    <input type="hidden" name="modifyId" class="image">


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form','upload','tfApi'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$,
            API = layui.tfApi;



        /*
        去掉上传截图功能
        $("#AjaxFileData").change(function(){
            //$("#picShow").attr("src",URL.createObjectURL($(this)[0].files[0]));
            var file = $('#AjaxFileData').get(0).files[0];
            var reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload=function(e){
                //读取成功后返回的一个参数e，整个的一个进度事件
                console.log(e);
                //选择所要显示图片的img，要赋值给img的src就是e中target下result里面
                //的base64编码格式的地址
                $('#picShow').get(0).src = e.target.result;
            }
        });
        */


        form.on('select(invoiceSta)',function (data) {
            var _sta = data.value;
            if(_sta == 2){
                $(".bh-item").hide();
                $("input[type='text']").attr('lay-verify','');
            }else {
                $("input[type='text']").attr('lay-verify','required');
                $(".bh-item").show();
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            var expressCode = $("input[name='expressCode']").val(),
                billCode = $("input[name='billCode']").val(),
                billNumber = $("input[name='billNumber']").val(),
                formData = new FormData();
            //picFiles = $("#AjaxFileData")[0].files[0],
            //picObjs = document.getElementById("AjaxFileData");

            //console.log("picObjs.value--v",picObjs.value);

            if(status == 2 && remark == ''){ //驳回状态，必须填写备注信息；
                layer.alert("发票驳回，请填写备注信息（驳回原因）！");
                return  false;
            }

            /*
            if(status == 2 || picObjs.value == ""){ //驳回
                picFiles = new File($("#AjaxFileData"), "");

            }else {
                picFiles = $("#AjaxFileData")[0].files[0];
                var imgType = (picFiles.name.substr(picFiles.name.lastIndexOf("."))).toLowerCase();
                if (imgType != ".jpg" && imgType != ".gif" && imgType != ".jpeg" && imgType != ".png") {
                    layer.alert("您上传图片的类型不符合(.jpg|.jpeg|.gif|.png)！");
                    return false;
                }
                if (($("#AjaxFileData")[0].files[0].size / 1024) > (5 * 1024)) {
                    layer.alert("上传图片不得大于 5M");
                    return;
                }


            }
            */


            formData.append("expressCode", expressCode);
			formData.append("billCode", billCode);
			formData.append("billNumber", billNumber);


            console.log("formData===222=="+formData);

            $.ajax({
                url: API.CURL + '/service/updexpress',
                type: 'post',
                data: formData,
                processData: false,
                contentType: false,
                success: function (res) {
                    console.log("ok=="+res);
                    var data = JSON.parse(res);
                    if(data.code == 0){
                        var index = layer.alert('修改成功！', {
                            title: '最终的提交信息'
                        }, function () {

                            // 关闭弹出层
                            layer.close(index);
                            parent.location.reload();

                        });
                    }
                }
            });


            return false;
        });
    });
</script>
</body>
</html>